#include "DataTypeFactory.h"
#include "../Error.h"
#include "Int8.h"
#include "Int16.h"
#include "Int32.h"
#include "Int64.h"
#include "UInt8.h"
#include "UInt16.h"
#include "UInt32.h"
#include "UInt64.h"
#include "Float32.h"
#include "Float64.h"
#include "Float128.h"
#include "String.h"
#include "Bool.h"
#include "TimeStamp.h"

std::map<int, const DataType *> DataTypeFactory::singletonObjects;

const DataType *DataTypeFactory::instanceFromIndex( unsigned int itype )
{
    if ( singletonObjects.size() == 0 )
    {
        //std::cout << "initializing objects" << std::endl;
        singletonObjects[INT8] = new Int8();
        singletonObjects[INT16] = new Int16();
        singletonObjects[INT32] = new Int32();
        singletonObjects[INT64] = new Int64();
        singletonObjects[UINT8] = new UInt8();
        singletonObjects[UINT16] = new UInt16();
        singletonObjects[UINT32] = new UInt32();
        singletonObjects[UINT64] = new UInt64();
        singletonObjects[FLOAT32] = new Float32();
        singletonObjects[FLOAT64] = new Float64();
        singletonObjects[FLOAT128] = new Float128();
        singletonObjects[STRING] = new String();
        singletonObjects[BOOL] = new Bool();
        singletonObjects[TIMESTAMP] = new TimeStamp();
    }
    if ( singletonObjects.count( itype ) == 0 )
    {
        throw IOError( "Unimplented data type" );
    }
    return singletonObjects[itype];
}

const int DataTypeFactory::INT8 = 1;
const int DataTypeFactory::INT16 = 2;
const int DataTypeFactory::INT32 = 3;
const int DataTypeFactory::INT64 = 4;
const int DataTypeFactory::UINT8 = 5;
const int DataTypeFactory::UINT16 = 6;
const int DataTypeFactory::UINT32 = 7;
const int DataTypeFactory::UINT64 = 8;
const int DataTypeFactory::FLOAT32 = 9;
const int DataTypeFactory::FLOAT64 = 10;
const int DataTypeFactory::FLOAT128 = 11;
const int DataTypeFactory::STRING = 32;
const int DataTypeFactory::BOOL = 33;
const int DataTypeFactory::TIMESTAMP = 68;

